/*

    @敌机

*/

var eNum=250;
var enemys=[];//用来保存存在的敌机

//创建敌机
function createEnemy(){
    if(score>=20000){
        eNum=180;
    }
    if(score>=60000){
        eNum=140;
    }
    if(score>=90000){
        eNum=100;
    }
    if(score>=120000){
        eNum=80;
    }
    if(score>=200000){
        eNum=40;
    }
    if(score>=250000){
        eNum=20;
    }
    var num=rand(0,eNum);
    var e=null;
    if(num<=10){
        if(num>9){
            e=new Enemy(3);
            enemys.push(e);
        } else if(num>6){
            e=new Enemy(2);
            enemys.push(e);
        } else {
            e=new Enemy(1);
            enemys.push(e);
        }
        
    }
}

function Enemy(type){
    this.type=type;
    this.isDelete=false;
    this.isBol=false;
    this.showIndex=0;
    if(type==1){
        //小
        this.hp=100;
        this.speed=rand(3,10);
        this.showMax=4;
        this.score=100;
        this.x=rand(0,canvas.width-38);
        this.y=-34;
        this.w=38;
        this.h=34;
        this.img=enemyImg1;
    } else if(type==2){
        //中
        this.hp=300;
        this.speed=rand(3,8);
        this.showMax=5;
        this.score=300;
        this.x=rand(0,canvas.width-46);
        this.y=-64;
        this.w=46;
        this.h=64;
        this.img=enemyImg2;
    } else {
        //大
        this.hp=600;
        this.speed=rand(3,6);
        this.showMax=9;
        this.score=600;
        this.x=rand(0,canvas.width-110);
        this.y=-164;
        this.w=110;
        this.h=164;
        this.img=enemyImg3;
    }
}

Enemy.prototype._move=function (){
    this.y+=this.speed;
    if(this.y>=canvas.height){
        this.isDelete=true;
    }
}
Enemy.prototype.draw=function (){
    this._move();
    if(this.hp<=0){
        this.isBol=true;
        this.showIndex++;
        if(this.showIndex==this.showMax){
            this.isDelete=true;
            score+=this.score;
            p.innerHTML="得分："+score+"分";
        }
    }
    ctx.beginPath();
    
    ctx.drawImage(this.img,this.showIndex*this.w,0,this.w,this.h,this.x,this.y,this.w,this.h);
}



